<#assign attribute=getContentAttribute(content.id)/>
<@_category id=content.categoryId;category>
    <#assign
        temp=getContentPage(attribute.text!'',pageIndex)
        page=temp.page
        text=temp.text
    />
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>${content.title} - ${(category.name)!}</title>
    <meta name="keywords" content="<#list getKeywords(content.title) as a>${a}<#sep>,</#list>"/>
    <meta name="description" content="${(content.description)!}"/>
	<style>
		.text-center{text-align:center;}
		.clearfix::after{display: block;clear: both;content: "";}
		article #content img,article #content table,article figure img{max-width:100%;}
		article #content,{width:100%;overflow: auto;}
	</style>
</head>
<body>
    <header>
        <h1>${(site.name)!}</h1>
    </header>
    <nav>
        <a href="${base}">Home page</a>
<@_categoryList>
    <#list page.list as a>
        <a href="${a.url!}" target="_blank">${a.name}</a>
    </#list>
</@_categoryList>
    </nav>
    <main>
        <article>
            <h1><a href="${content.url!}">${content.title}</a></h1>
            <p><#if content.copied>Source:<a href="${(attribute.sourceUrl)!}" target="_blank">${(attribute.source)!}</a></#if> ${content.author!} ${content.editor!} ${content.publishDate?datetime} Views:<em>loading...</em></p>
            <div id="content" class="clearfix">${(text?no_esc)!}</div>
        <#if content.hasProducts>
            <div>
                <form action="${site.dynamicPath}member/order.html">
                <@_contentProductList contentId=content.id fileTypes='video,audio,other'>
                    <#list page.list as product>
                        <label>
                            <input type="radio" name="productId" value="${product.id}"/>
                            <#if product.cover?has_content>
                                <img src="<@_thumb path=product.cover width=30 height=30/>" title="${product.title}" alt="${product.title}" style="max-width:30px;max-height30px;border:1px solid;"/>
                            </#if>
                            ${product.title}
                        </label>
                    </#list>
                </@_contentProductList>
                    <label>Price:</label><span class="price">0</span>
                    <input type="number" name="quantity" value="1"/>
                    <input type="submit" value="Buy"/>
                </form>
            </div>
        </#if>
        <#if content.hasFiles>
			<@_contentFileList contentId=content.id fileTypes='video,audio,other'>
				<#list page.list as file>
					<p><a href="${(file.filePath)!}" target="_blank">${(file.filePath)!}</a></p>
				</#list>
			</@_contentFileList>
        </#if>
        <#if content.hasImages>
			<figure class="text-center">
             <@_contentFileList contentId=content.id fileTypes='image'>
                 <#list page.list as file>
                     <img src="${(file.filePath)!}" alt="${(file.description)!}"/>
					 <p>ͼ${file?counter} ${(file.description)!}</p>
                 </#list>
             </@_contentFileList>
            </figure>
        </#if>
        <#if content.tagIds?has_content>
            <p>
                Tags:
                <@_tag ids=content.tagIds>
                    <#list map as key,tag>
                        <em>${tag.name}</em>
                    </#list>
                </@_tag>
            </p>
        </#if>
            <div>
                ${content.scores!} scores
                <#if user?has_content>
                    <@_userScore userId=user.id itemType='content' itemId=content.id>
                        <a href="javascript:unscore(${content.id});">Cancel rating</a>
                        <#assign stared=true/>
                    </@_userScore>
                    <#if !stared?has_content><a href="javascript:score(${content.id});">Score</a></#if>
                </#if>
            </div>
            <div>
                <#if !page.firstPage>
                    <a href="${getPage(content.url,page.prePage)}">Previous page</a>
                <#else>
                    <span>Previous page</span>
                </#if>
                <#list 1..page.totalCount as n>
                    <#if n=page.pageIndex>
                        ${n}
                    <#else>
                        <a href="${getPage(content.url,n)}">${n}</a>
                    </#if>
                </#list>
                <#if !page.lastPage>
                    <a href="${getPage(content.url,page.nextPage)}">Next page</a>
                <#else>
                    <span>Next page</span>
                </#if>
            </div>
            <div>
                <@_contentList categoryId=category.id endPublishDate=content.publishDate orderField='publishDate' pageIndex=2 pageSize=1><#if 2=page.pageIndex><#list page.list as a><a href="${a.url!}">Previous:${a.title}</a></#list></#if></@_contentList>
                <@_contentList categoryId=category.id startPublishDate=content.publishDate orderField='publishDate' orderType='asc' pageIndex=1 pageSize=1><#list page.list as a><a href="${a.url!}">Next:${a.title}</a></#list></@_contentList>
            </div>
            <div>
         <#macro merge name value><#if !.vars[name]??><@"<#assign ${name}=''>"?interpret /></#if><#if value?has_content><@"<#assign ${name}=${name}+'${value},'>"?interpret /></#if></#macro>
         <@_commentList contentId=content.id pageSize=10>
            <#list page.list as a>
                <@merge 'userIds' a.userId!/>
                <@merge 'userIds' a.replyUserId!/>
            </#list>
            <@_sysUser ids=userIds!><#assign userMap=map!/></@_sysUser>
            <#list page.list as a>
                <dl>
                    <dt>${(userMap[a.userId?string].nickName)!}<#if a.replyUserId?has_content> reply ${(userMap[a.replyUserId?string].nickName)!}</#if>:</dt>
                    <dd>
                        <div>${a.text!}</div>
                    </dd>
                </dl>
            </#list>
        </@_commentList>
            </div>
        </article>
        <aside>
            <h3>Popular content</h3>
            <ul>
<@_contentList categoryId=category.id containChild=true orderField='clicks' pageSize=10>
    <#list page.list as a>
                <li><a href="<#if a.onlyUrl>${site.dynamicPath}content/redirect?id=${a.id}<#else>${a.url!}</#if>" target="_blank">${a.title}</a><span>${a.clicks}</span></li>
    </#list>
</@_contentList>
            </ul>
        </aside>
    </main>
    <footer>
        Copyright &copy; ${.now?string('yyyy')}
    </footer>
    <script src="${site.dynamicPath!}resource/js/jquery-1.12.4.min.js"></script>
    <#if content.hasProducts>
    <script>
    $('input[name=productId]').change(function(){
        var selectedProductId=this.value;
        if(selectedProductId){
            $.getJSON('${site.dynamicPath!}api/directive/contentProduct?id='+selectedProductId, function(data){
                if($('input[name=productId]:checked').val() == selectedProductId){
                    $('.price').text(data.object.price);
                    if(data.object.minQuantity){
                        $('input[name=quantity]').attr('min', data.object.minQuantity);
                    }
                    if(data.object.maxQuantity && data.object.maxQuantity<data.object.inventory){
                        $('input[name=quantity]').attr('max', data.object.maxQuantity);
                    }else{
                        $('input[name=quantity]').attr('max', data.object.inventory);
                    }
                }
            });
        }
    })
    </script>
    </#if>
    <script>
        $.getJSON('${site.dynamicPath!}api/contentClick?id=${content.id}', function(data){
            $('article p em').text(data.clicks);
        });
    </script>
    <script>
function score(contentId){
    $.getJSON('${site.dynamicPath!}score/score?itemId='+contentId+'&itemType=content&_csrf=<@_csrfToken/>', function(data){
        alert("Score ok!");
        location.reload();
    });
}
function unscore(contentId){
    $.getJSON('${site.dynamicPath!}score/unscore?itemId='+contentId+'&itemType=content&_csrf=<@_csrfToken/>', function(data){
        alert("Cancel ok!");
        location.reload();
    });
}
    </script>
	<script src="${site.dynamicPath}resource/ueditor/ueditor.parse.min.js"></script>
	<script>
	uParse('#content',{rootPath: '${site.dynamicPath}resource/ueditor/'});
	</script>
    <script>
    var itemString="itemType=content&itemId=${content.id}";
    </script>
    <script src="${site.dynamicPath}resource/js/cms.analytics.js"></script>
    <script>
        var ca = cmsAnalytics();
        var url='${site.dynamicPath}api/visit/record';
        if("string" ==typeof itemString){
            url=url+"?"+itemString;
        }
        ca.setDomain('${domain.name}');
        ca.setPath('/');
        ca.report(url);
    </script>
</body>
</html>
</@_category>